﻿Imports UtilPadrao
Public Class frmLogin_

#Region "Variáveis"

    Private objUsuario As New Controle.ctrUsuario

#End Region

#Region "Constantes"

    Const usuarioSeguranca As String = "admin"
    Const senhaSeguranca As String = "senhaseg"

#End Region

#Region "Propriedades"

    Public Property codUsuario As Integer
    Public Property nomeUsuario As String
    Public Property codGrupo As Integer
    Public Property loginRealizado As Boolean
    Public Property usuarioInterno As Boolean

#End Region

#Region "Eventos"

    Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click

        Dim drUsuario As DataRow

        Try

            If MyBase.validaCampos Then

                If (String.Equals(Me.txtLogin.Text, FronteiraPadrao.frmLogin.usuarioPadrao) AndAlso String.Equals(Me.txtSenha.Text, FronteiraPadrao.frmLogin.senhaPadrao)) OrElse _
                    (String.Equals(Me.txtLogin.Text, usuarioSeguranca) AndAlso String.Equals(Me.txtSenha.Text, senhaSeguranca)) Then

                    Me.codUsuario = 0
                    Me.usuarioInterno = True
                    Me.loginRealizado = True
                    Me.Close()

                Else

                    drUsuario = Me.objUsuario.selecionarUsuario(Me.txtLogin.Text, Me.txtSenha.Text)
                    If drUsuario Is Nothing Then
                        Me.epAcesso.SetError(txtLogin, "Dados incorretos.")
                        Me.loginRealizado = False
                    Else
                        Me.codUsuario = conversao.toInt32(drUsuario.Item("codUsuario"))
                        Me.nomeUsuario = conversao.nuloParaVazio(drUsuario.Item("nome"))
                        Me.codGrupo = conversao.toInt32(drUsuario.Item("codGrupo"))

                        Me.loginRealizado = True
                        Me.Close()
                    End If

                End If

            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub cmdSair_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSair.Click
        Me.codUsuario = 0
        Me.nomeUsuario = String.Empty
        Me.loginRealizado = False
        Me.Close()
    End Sub

#End Region


End Class